import React from 'react';
import {
    StyleSheet,
    View,
    Image,
    InteractionManager,
    Text,
} from 'react-native';
import Common from '../common/constants';
import {Carousel, Grid, SearchBar, List, Brief, WhiteSpace} from 'antd-mobile';
import { getUserInfo } from '../actions/userAction';

import LoginContainer from '../containers/LoginContainer';
import RegisterContainer from '../containers/RegisterContainer';



export default class Mine extends React.Component{

    constructor(props) {
        super(props);
    }

    componentWillMount() {
        if(global.user.accessTicket == ''){
            this._login();
        }else{
            const {dispatch} = this.props;
            dispatch(getUserInfo());
        }
    }

    componentDidMount() {
        
        
    }

    _login() {
        this.props.navigator.push({
            component: LoginContainer,
        })
    }

    _logout() {

        storage.remove({key: 'userlogininfo'});
        global.user.accessTicket = '';
        global.user.userId = '';

        this.props.mineReducer.userinfo = {};

        this.props.navigator.push({
            component: LoginContainer,
        })
    }

    render(){

        console.log('mine props');
        console.log(this.props);
        let { userinfo } = this.props.mineReducer;
        let { getting } = this.props.mineReducer;

        return (
            <View style={styles.main}>
              <List>
                <List.Item
                  arrow="horizontal"
                  //thumb={<Image source={require('../imgs/t1.png')} />}
                  //thumb={<Image source={{uri: "https://zos.alipayobjects.com/rmsportal/AiyWuByWklrrUDlFignR.png"}} />}
                  thumb="https://zos.alipayobjects.com/rmsportal/AiyWuByWklrrUDlFignR.png"
                  multipleLine
                  onClick={() => {}}
                  style={styles.user}
                >
                  <WhiteSpace size="lg" />
                  {
                      getting ? '登录中' :
                      userinfo.username ? userinfo.username : '未实名'
                  }<List.Item.Brief>{userinfo.mobile}</List.Item.Brief>
                  <WhiteSpace size="lg" />
                </List.Item>
              </List>

              <WhiteSpace size="lg" />
              <List>
                <List.Item
                  thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
                  arrow="horizontal"
                  onClick={() => {}}
                >
                    我的积分
                </List.Item>
                <List.Item 
                  thumb="https://zos.alipayobjects.com/rmsportal/UmbJMbWOejVOpxe.png" 
                  arrow="horizontal">
                    我的订单
                </List.Item>
              </List>

              <WhiteSpace size="lg" />
              <List>
                <List.Item
                  thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
                  arrow="horizontal"
                  onClick={() => {}}
                >
                    设置
                </List.Item>
              </List>

              <WhiteSpace size="lg" />
              <List>
                <List.Item
                  thumb="https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png"
                  onClick={this._logout.bind(this)}
                  style={styles.logout}
                >
                    退出登录
                </List.Item>
              </List>

              

            </View>
        );
    }
}

const styles = StyleSheet.create({

    main : {
        marginTop : 65
    },

    

})